#include "icache/still_image_id.h"
#include "imglib/io.h"
#include "mswin/file_dir.h"

namespace icache {

still_image_id_deserializer the_still_image_id_deserializer;

bool still_image_id::equal(const item_id & i) const 
{
	const still_image_id * rhs = dynamic_cast<const still_image_id *>(&i);
	if (rhs == 0)
		return false;
	return _stricmp(path.c_str(), rhs->path.c_str()) == 0; 
}

string still_image_id::name() const
	{ return mswin::basename(path); }

void still_image_id::serialize(std::ostream & o) const
	{ o << "copy of image:\n" << path; }

void still_image_id::load(byte_image & im) const
	{ img::our_gdiplus_multireader().read(path, im); }

void still_image_id::request() const
	{ assert(!"n/a"); }

//

item_id_sptr still_image_id_deserializer::parse(std::istream & i) const 
{
	std::string s;
	getline(i, s);
	if (s != "copy of image:")
		return item_id_sptr();
	getline(i, s);
	return item_id_sptr(new still_image_id(s));
}

} //namespace icache
